﻿/*
 * Copyright © 2020, Wuxi Safover Intelligent Technology Co., Ltd. All rights reserved.
 * 
 * 无锡安永智能科技有限公司版权所有，未经许可，不得用于商业用途
 * 
 * Visit: https://www.safover.com/ 
 */

using System;
using Safover.LidarCollector.Extensions;

namespace Om.Default
{
    internal class MainBoardPacket : NJOpticalMaserPacket
    {
        public override PacketType PacketType => PacketType.MainBoard;

        /// <summary>
        /// 开光次数
        /// </summary>
        public int CountOfLasarOpened => BitConverter.ToInt32(RawBytes, 18);

        /// <summary>
        /// 激光器工作时长
        /// </summary>
        public TimeSpan TimeofWorking => TimeSpan.FromSeconds(BitConverter.ToInt32(RawBytes, 22));

        /// <summary>
        /// 激光头湿度
        /// </summary>
        public int PuhHumidity => RawBytes[28];

        /// <summary>
        /// 激光是否开启
        /// </summary>
        public bool IsLaserOpened => RawBytes[32].IsBitSet(0);

        /// <summary>
        /// 主控未是否自检中
        /// </summary>
        public bool IsMainBoardSelfChecking => RawBytes[32].IsBitSet(5);

        /// <summary>
        /// 错误位存在异常
        /// </summary>
        public bool HasError => RawBytes[33] > 0;

        /// <summary>
        /// 内触发频率
        /// </summary>
        public int InternalTriggerFrequency 
        {
            get 
            {
                return (RawBytes[7] << 16) | (RawBytes[8] << 8) | RawBytes[9];
            } 
        }

        /// <summary>
        /// 外触发频率
        /// </summary>
        public int ExternalTriggerFrequency
        {
            get
            {
                 return (RawBytes[4] << 16) | (RawBytes[5] << 8) | RawBytes[6];
            }
        }


        public MainBoardPacket(byte[] rawBytes) : base(rawBytes)
        { }
    }

}
